from __future__ import unicode_literals
# 地图坐标图

# 旧版导入方式
from pyecharts import Geo
# 旧版本测试地理图
data = [
  ("海门", 95), ("鄂尔多斯", 15), ("招远", 12), ("舟山", 12), ("齐齐哈尔", 14), ("盐城", 15),
  ("赤峰", 16), ("青岛", 18), ("乳山", 18), ("金昌", 19), ("泉州", 21), ("莱西", 21),
  ("日照", 21), ("胶南", 22), ("南通", 23), ("拉萨", 24), ("云浮", 24), ("梅州", 25),
  ("文登", 25), ("上海", 25), ("攀枝花", 25), ("威海", 25), ("承德", 25), ("厦门", 26),
  ("汕尾", 26), ("潮州", 26), ("丹东", 27), ("太仓", 27), ("曲靖", 27), ("烟台", 28),
  ("福州", 29), ("瓦房店", 30), ("即墨", 50), ("抚顺", 31), ("玉溪", 31), ("张家口", 31),
  ("阳泉", 31), ("莱州", 42), ("湖州", 32), ("汕头", 32), ("昆山", 33), ("宁波", 33),
  ("湛江", 33), ("揭阳", 44), ("荣成", 54), ("连云港", 35), ("葫芦岛", 35), ("常熟", 36),
  ("东莞", 36), ("河源", 36), ("淮安", 56), ("泰州", 36), ("南宁", 47), ("营口", 37),
  ("惠州", 37), ("江阴", 67), ("蓬莱", 57), ("韶关", 38), ("嘉峪关", 78), ("广州", 38),
  ("延安", 38), ("太原", 69), ("清远", 59), ("中山", 39), ("昆明", 79), ("寿光", 40),
  ("盘锦", 40), ("长治", 61), ("深圳", 51), ("珠海", 42), ("宿迁", 73), ("咸阳", 43),
  ("铜川", 44), ("平度", 64), ("佛山", 54), ("海口", 44), ("江门", 75), ("章丘", 45),
  ("肇庆", 46), ("大连", 67), ("临汾", 57), ("吴江", 47), ("石嘴山", 9), ("沈阳", 50),
  ("苏州", 50), ("茂名", 60), ("嘉兴", 41), ("长春", 51), ("胶州", 52), ("银川", 52),
  ("张家港", 52), ("三门峡", 53), ("锦州", 54), ("南昌", 54), ("柳州", 54), ("三亚", 54),
  ("自贡", 56), ("吉林", 56), ("阳江", 57), ("泸州", 57), ("西宁", 57), ("宜宾", 58),
  ("呼和浩特", 58), ("成都", 58), ("大同", 58), ("镇江", 59), ("桂林", 59), ("张家界", 59),
  ("宜兴", 59), ("北海", 60), ("西安", 61), ("金坛", 62), ("东营", 62), ("牡丹江", 63),
  ("遵义", 63), ("绍兴", 63), ("扬州", 64), ("常州", 64), ("潍坊", 65), ("重庆", 66),
  ("台州", 67), ("南京", 67), ("滨州", 70), ("贵阳", 71), ("无锡", 71), ("本溪", 71),
  ("克拉玛依", 72), ("渭南", 72), ("马鞍山", 72), ("宝鸡", 72), ("焦作", 75), ("句容", 75),
  ("北京", 79), ("徐州", 79), ("衡水", 80), ("包头", 80), ("绵阳", 80), ("乌鲁木齐", 84),
  ("枣庄", 84), ("杭州", 84), ("淄博", 85), ("鞍山", 86), ("溧阳", 86), ("库尔勒", 86),
  ("安阳", 90), ("开封", 90), ("济南", 92), ("德阳", 93), ("温州", 95), ("九江", 96),
  ("邯郸", 98), ("临安", 99), ("兰州", 99), ("沧州", 100), ("临沂", 103), ("南充", 104),
  ("天津", 105), ("富阳", 106), ("泰安", 112), ("诸暨", 112), ("郑州", 113), ("哈尔滨", 114),
  ("聊城", 116), ("芜湖", 117), ("唐山", 119), ("平顶山", 119), ("邢台", 119), ("德州", 120),
  ("济宁", 120), ("荆州", 127), ("宜昌", 130), ("义乌", 132), ("丽水", 133), ("洛阳", 134),
  ("秦皇岛", 136), ("株洲", 143), ("石家庄", 147), ("莱芜", 148), ("常德", 152), ("保定", 153),
  ("湘潭", 154), ("金华", 157), ("岳阳", 169), ("长沙", 175), ("衢州", 177), ("廊坊", 193),
  ("菏泽", 194), ("合肥", 229), ("武汉", 273), ("大庆", 279)]

geo = Geo("全国主要城市空气质量", "data from pm2.5", title_color="b",
        title_pos = "center", width = 1200,
        height = 600, background_color = '#404a59')
attr,value=geo.cast(data)
geo.add("",attr,value,visual_range=[0,200],visual_text_color='#fff',symbol_size=15,is_visualmap=True)
geo.render("空气质量图.html")


# effect 样式
attr, value = geo.cast(data)
geo.add("", attr, value, type="effectScatter", is_random=True, effect_scale=5)
geo.render("effect.html")

# headmap 样式
geo.add("", attr, value, type="heatmap", is_visualmap=True, visual_range=[0, 300],
       visual_text_color='#fff')
geo.render("headmap.html")

# 地图坐标系线图
# 应用场景：分析数据出行

from pyecharts import GeoLines,Style
style=Style(title_top="#fff",title_pos="center",width=1200,height=600,background_color='#404a59')
style_geo=style.add(is_label_show=True,line_curce=0.2,line_opacity=0.6,legend_text_color='#eee',
                   legend_pos='right',geo_effect_symbol='plane',geo_effect_symbolsize=15,label_color=['#a6c84c','#ffa022','#46bee9'],
                   label_pos='right',label_formatter="{b}",label_text_color="#eee")
data_guangzhou=[
  ["广州", "上海"],
  ["广州", "北京"],
  ["广州", "呼和浩特"],
  ["广州", "太原"],
  ["广州", "长沙"],
  ["广州", "吐鲁番"]
]
geolines=GeoLines("示例 -lg",**style.init_style)
geolines.add("从广州出发",data_guangzhou,**style_geo)
geolines.render("示例.html")

# 关系图
from pyecharts import Graph
nodes = [{"name": "a", "symbolSize": 10},
        {"name": "b", "symbolSize": 20},
        {"name": "c", "symbolSize": 30},
        {"name": "d", "symbolSize": 40},
        {"name": "e", "symbolSize": 50},
        {"name": "f", "symbolSize": 40},
        {"name": "g", "symbolSize": 30},
        {"name": "h", "symbolSize": 20}]

links=[]
for i in nodes:
    for j in nodes:
        links.append({"source": i.get('name'), "target": j.get('name')})
graph =Graph("关系图-环形布局示例")
graph.add("",nodes,links,is_label_show=True,graph_repulsion=8000,graph_layout='circular',label_text_color=None)
graph.render("关系图.html")


# 词云
# 数据指标随机生成的，名字是安装本期活动顺序写的

from pyecharts import WordCloud

name = [
  '喵呜', '四方', '映琴', '梧桐', 'Ray',
  '子逐', '小明', '小小外星人', '大熊喵喵喵', 'Tony', '木夫',
  '平凡人', '不染', 'W.', '白饭', 'vicky',
  '不是', '挖掘机', '陌影', '赛茜']
value = [
  10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,
  965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
wordCloud=WordCloud(width=1300,height=620)
wordCloud.add("",name,value,word_size_range=[20,100])
wordCloud.render("词云.html")

# 图表

from pyecharts import Bar
bar=Bar("我的第一个图表","副标题")
# print_echarts_options() 可以打印所有配置项 用于配置生成图表
bar.add("分类",["A","B","C","D","E","F"],[15,18,35,66,6,88])
bar.render("bar.html")

# 柱状图
from pyecharts import Bar

attr = ["{}月".format(i) for i in range(1,13)]
v1 = [2.0,4.9,7.0,23.2,25.6,76.7,135.6,162.2,32.6,20.0,6.4,3.3]
v2 = [2.6,5.9,9.0,26.4,28.7,70.7,175.6,182.2,48.7,18.8,6.0,2.3]

bar = Bar("柱状图示例")
bar.add("增长数",attr,v1,mark_line=["average"],mark_point=["max","min"])
bar.add("取关数",attr,v2,mark_line=["average"],mark_point=["max","min"])
bar.render("柱状图.html")

# 饼图
from pyecharts import Pie

attr = ["算法","产品","大数据","数据分析","Python","数据可视化"]
v1 = [11,12,13,10,10,10]
v2 = [19,21,32,20,20,33]

pie= Pie("饼图-玫瑰图示例-DataScience",title_pos='center',width=900)
pie.add("品种A",attr,v1,center=[25,50],is_random=True,redius=[30,75],rosetype='redius')
pie.add("品种B",attr,v2,center=[75,50],is_random=True,redius=[30,75],rosetype='area',is_legend_show=False,is_label_show=True)
pie.render("饼图.html")

# 如果使用的是 自定义类，直接调用自定义类示例即可

from pyecharts import Bar,Line,Overlap
attr = ["A","B","C","D","E","F"]
v1 = [10,20,30,40,50,60]
v2 = [38,28,58,48,88,68]
bar =Bar("Line-Bar 示例")
bar.add("bar",attr,v1)
line = Line()
line.add("line",attr,v2)
overlap = Overlap()
overlap.add(bar)
overlap.add(line)
overlap.render("自定义示例.html")